package com.ops.wechat.core;

import com.ops.memcache.MemCache;
import com.ops.uitl.data.DataMap;
import com.ops.uitl.data.DatasetList;
import com.ops.uitl.data.IData;
import com.ops.uitl.data.IDataset;
import com.ops.uitl.tapestry.PageData;
import com.ops.wechat.dao.CommonDAO;
import org.apache.log4j.Logger;
import org.apache.tapestry.IRequestCycle;

/**
 * lenovo
 * 2017/5/10
 * wechat
 */
public abstract class CommonUrl extends WechatPage {

	private Logger log = Logger.getLogger(CommonUrl.class);

	public abstract void setInfos(IDataset list);

	public abstract void setMp(IData data);


	/**
	 * @Describe 测试数据源、一级缓存方法
	 * @Method initPage
	 * @Param
	 * @Author liyl@asiainfo.com
	 * @Date 2017/5/10 21:01
	 */
	public void initPage(IRequestCycle cycle) throws Exception {
		PageData pd = getPageData();
		CommonDAO dao = new CommonDAO(pd);
		//测试codecode
		IData param = new DataMap();
		param.put("SERIAL_NUMBER","13999988696");
		log.error("通过CodeCode调用数据库：" + dao.getActivityInfo(param));
		//测试数据源
		log.error("通过数据库获取当前时间："+ dao.getSys_date());
		//测试一级缓存memcache
		log.error("通过一级缓存获取测试参数："+ MemCache.memcache_Get("testMem"));

		IDataset list = new DatasetList();
		for(int i = 0;i < 5;i++){
			IData data = new DataMap();
			data.put("BTN_NAME","按钮" + i);
			list.add(data);
		}
		setInfos(list);

		IData mp = new DataMap();
		mp.put("FLAG","1");
		setMp(mp);
	}

	/**
	 * @Describe 测试AJAX请求
	 * @Method testAjax
	 * @Param
	 * @Author liyl@asiainfo.com
	 * @Date 2017/5/11 22:24
	 */
	public void testAjax(IRequestCycle cycle) throws Exception {
		PageData pd = getPageData();
		IData data = pd.getData();
		IData retdata = new DataMap();
		retdata.put("RESULT_CODE","0");
		retdata.put("TESTCODE",data.getString("testcode"));
		pd.setAjaxData(retdata);
	}
}
